<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="jpa.*" %>
<%@ page import="pkg.*" %>
<%@ page import="java.io.PrintStream" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%!
private List<Page> pagesPrinted = new ArrayList<Page>();

private void reset() {
	pagesPrinted.clear();
}
private void printPage(Page p, JspWriter out, IStatelessBean statelessBean) throws IOException {
	boolean visited = false;
	for(Page page : pagesPrinted) {
		if(p.getPgId() == page.getPgId()) visited = true;
	}
	if(visited) return;
	pagesPrinted.add(p);
	out.println("<li>" + p.getPgTitle() + "</li>");
	out.println("<ul>");
	//force commit
	for(Link l : statelessBean.sortLinks(p.getLinks2())) {
		printPage(l.getPage1(), out, statelessBean);
	}
	out.println("</ul>");
}
%>
<%
IStatelessBean statelessBean = (IStatelessBean)session.getAttribute("statelessBean");
Page root = statelessBean.getRootPage();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Here's my dump</h1>
<ul><%
reset();
printPage(statelessBean.getRootPage(), out, statelessBean); %></ul>
</body>
</html>